<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/vue/html.js"></script>
    <script src="../../js/vue/jquery/jquery.js"></script>
</head>
<body>
<div id="app">
    <form id="formId">
        <input type="hidden" name="id" v-model="user.id">
        名称：<input type="text" name="name" v-model="user.name"><br>
        年龄：<input type="text" name="age" v-model="user.age"><br>
        <input type="button" id="btn" @click="submitForm()" value="提交"></input>
    </form>
</div>
<script>
    //地址栏
    //获取url上的请求参数
    function getParams() {
        //获取问号及问号后面的内容
        var url = window.location.search;
        var params = new Object();
        if (url.indexOf("?") != -1) {
            //截取问号后面的内容,再使用&分割多个属性
            var arr = url.substr(1).split("&");
            for (var i = 0; i < arr.length; i++) {
                //使用=分割为keyvalue
                var keyValue = arr[i].split("=");
                params[keyValue[0]] = keyValue[1];
            }
        }
        return params;
    }
    var vue = new Vue({
        el: "#app",
        data:{
            user:[]
        },
        methods:{
            submitForm:function () {
                $.post("http://localhost:8888/employee/put",$("#formId").serialize(),function (data) {
                    if(data==200){
                        location.href="views/vue/vur-list.html"
                    }else {
                        console.log(data.msg)
                    }
                })
            }
        },
        mounted:function () {
            var _this=this;
            $.get("http://localhost:8888/employee/getOne",{id:getParams().id},function (data) {
                _this.user = data;
                console.log(data)
            })
        }
    })
</script>
</body>
</html>